﻿@{
    ViewBag.Title = "文章管理";
}
<div class="header">
    <h1>@ViewBag.Title</h1>
</div>
<ul class="breadcrumb">
    <li>@Html.ActionLink("Home", "Index", "Home")</li>
    <li>@Html.ActionLink("Articles", "Index")</li>
    <li class="active">Article</li>
</ul>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="btn-toolbar">
            <a class="btn btn-primary"><i class="fa fa-plus"></i> 添加 Article</a>
            <div class="btn-group">
            </div>
        </div>
        <div class="well">
            <div class="form-inline">
                <label>栏目</label><input id="combo_category" data-options="url:'@Url.Action("JsonTree", "Category")'" />
                <label>标题</label> <input id="textbox_title" class="input-easyui" style="width:280px" />
                <button class="btn-primary" id="btn_search"><i class="fa fa-search"></i>查询</button>
            </div>
            <table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>First name</th>
                        <th>Last name</th>
                        <th>Username</th>
                        <th style="width: 42px;"></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>1</td>
                        <td>Mark</td>
                        <td>Tompson</td>
                        <td>the_mark7</td>
                        <td>
                            <a href="@Url.Action("Edit", "Category",new{id="123"})"><i class="fa fa-pencil"></i></a>
                            <a href="#myModal" role="button" data-toggle="modal"><i class="fa fa-remove"></i></a>
                        </td>
                    </tr>

                </tbody>
            </table>
        </div>

        <div class="modal  fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 id="myModalLabel" class="modal-title">Delete Confirmation</h4>
                    </div>
                    <div class="modal-body">
                        <p><i class="fa fa-warning modal-icon"></i>Are you sure you want to delete the user?</p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                        <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


@section scripts{
    <script src="~/Scripts/jquery.easyui.min.js"></script>
    <script src="~/Scripts/Common.js"></script>

    <script type="text/javascript">
        $("#article_list").datagrid({
            loadMsg: '加载中……',
            pagination: true,
            url: '@Url.Action("JsonList", "Category", new { model = ViewData["Model"] })',
            columns: [
                [
                    { field: 'Id', title: 'Id', checkbox: true },
                    { field: 'name', title: '栏目' },
                    { field: 'Model', title: '模块' }
                ]
            ],
            toolbar: '#toolbar',
            idField: 'Id',
            onDblClickRow: function (rowIndex, rowData) { window.parent.addTab("修改栏目", "@Url.Action("Edit", "Category")/" + rowData.Id, "icon-page"); }
        });
        //查找
        $("#btn_search").click(function() {
            $("#article_list").datagrid('load', {
                title: $("#textbox_title").val(),
                input: $("#textbox_inputer").val(),
                category: $("#combo_category").combotree('getValue'),
                fromDate: $("#datebox_fromdate").datebox('getValue'),
                toDate: $("#datebox_todate").datebox('getValue')
            });
        });

        //修改事件
        function Create() {
            window.parent.addTab("添加栏目", "@Url.Action("Create", "Category")", "icon-page");
        }

        //修改事件
        function Eidt() {
            var rows = $("#article_list").datagrid("getSelections");
            if (!rows || rows.length < 1) {
                $.messager.alert("提示", "请选择要修改的行!");
                return;
            } else if (rows.length != 1) {
                $.messager.alert("提示", "仅能选择一行!");
                return;
            } else {
                window.parent.addTab("修改文章", "@Url.Action("Edit", "Category")/" + rows[0].Id, "icon-page");
            }
        }

        //删除
        function Delete() {
            var rows = $("#article_list").datagrid("getSelections");
            if (!rows || rows.length < 1) {
                $.messager.alert("提示", "未选择任何行!");
                return;
            } else if (rows.length > 0) {
                $.messager.confirm("确认", "您确定要删除所选行吗？", function(r) {
                    if (r) {
                        $.messager.progress();
                        $.each(rows, function(index, value) {
                            $.ajax({
                                type: "post",
                                url: "@Url.Action("Delete", "Category")",
                                data: { id: value.ModelID },
                                async: false,
                                success: function(data) {
                                }
                            });
                        });
                        $.messager.progress('close');
                        //清除选择行
                        rows.length = 0;
                        $("#article_list").datagrid('reload');
                    }
                });
                return;
            }
        }
    </script>
}
